package com.tnr.untils;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tnr.dto.PageParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MybatisUntil {
    public  static<T> Map<String,Object> GetPageData(PageParam pageParam, QueryAction queryAction){
        PageHelper.startPage(pageParam);
        List<T> list=queryAction.query();
        PageInfo<T> pageInfo= new PageInfo<T>(list);

        Map<String,Object> map=new HashMap<String, Object>();
        map.put("total", pageInfo.getTotal());//总记录数
        map.put("pgTotal", pageInfo.getPages());//当前记录数
        map.put("curr", pageInfo.getPageNum());//当前页数
        map.put("next", pageInfo.getNextPage());//下一页
        map.put("pre", pageInfo.getPrePage());//上一页
        map.put("pageSize",pageInfo.getPageSize());//每一页显示记录数
        map.put("currSize", pageInfo.getSize());//当前页记录数
        map.put("rows", pageInfo.getList());//当前页总数据
        return map;
    }

}
